package com.dy.排序.内排序.插入排序.希尔排序;

import java.util.Arrays;

/*
选定间隔d，进行插入排序，然后再逐渐减少d
O(n^(3/2))
 */
public class ShellSort {
    public static void shellSort(int nums[]) {
        int increment = nums.length / 2;
        while (increment > 0) {
            for (int i = increment; i < nums.length; i++) {
                int tmp = nums[i];
                int j = i;
                for (; j >0 && tmp < nums[j-increment]; j = j - increment) {
                    nums[j] = nums[j-increment];
                }
                nums[j] = tmp;
            }
            increment = increment / 2;
        }
    }

    public static void main(String[] args) {
        int[] nums = {3, 2, 4, 1, 5, 6};
        shellSort(nums);
        Arrays.stream(nums).forEach(System.out::println);
    }
}
